(*%F _fdata *)
(*# call(seg_name => null) *)
(*%E *)
(*# module(implementation=>off) *)
(*# data(seg_name => null) *)
(*# call(o_a_copy => off) *)
(*# check(stack=>off,
          index=>off,
          range=>off,
          overflow=>off,
          nil_ptr=>off) *)
DEFINITION MODULE PathFind;

(* Source code for JPI TopSpeed Modula-2 by

    Carl Neiburger
    169 N. 25th St.
    San Jose, Calif. 95116

    CompuServe No. 72336,2257

*)

FROM FioAsm IMPORT PathStr, PathTail; (* Same as JPI's FIO PathStr, PathTail *)

TYPE
    FilePtr = POINTER TO FileRec;

    FileRec = RECORD
         Name: PathStr;
         Next: FilePtr
    END;

PROCEDURE FindEnvStr( target : ARRAY OF CHAR; VAR string: ARRAY OF CHAR );

(* Finds a specified string in the environment and returns its arguments.
   For example, if you have set "path = e:\;e:\utils" then
   FindEnvStr( 'PATH', path ) will return with the variable
   path set equal to "E:\;E:\UTILS"
   The returned string will always be in upper case letters. 
   If target cannot be found, string will be empty. *)


PROCEDURE FindPath(PathName,
                   TargetName: ARRAY OF CHAR;
               VAR TargetPath: ARRAY OF CHAR): BOOLEAN;

(* Attempts to find the file name TargetName given an environment string,
   PathName. For example, if PATHFIND.MOD is in the F:\M2 directory, and you 
   have set the PATH string accordingly, 
   FindPath("PATH", "PATHFIND.MOD", filename) will return TRUE and 
   TargetPath will equal "F:\M2\PATHFIND.MOD" *)

PROCEDURE ParsePath(VAR Path: PathStr; 
                    VAR FileName: PathTail): BOOLEAN;

(* Parses the string Path into a valid directory path and a file name.

   You MUST INITIALIZE Path -- the string to parse -- AND a default FileName,
   to be returned if the path does not include a file name.  FileName can be 
   '' to return the path only, '*.*' for a wildcard reference to all files
   or some other default name.  The path will be returned without the final 
   backslash, so the root directory appears as 'D:'.

   If the path is not valid, ParsePath will return FALSE.
*)

PROCEDURE FileTree ( Path: PathStr ): FilePtr;
(* Returns a linked list of all files matching Path. If a file mask is not 
   specified, returns all files in directory. *)

PROCEDURE UnFileTree ( VAR Ptr : FilePtr );
(* Disposes of a file tree, returning the memory to the heap *)

END PathFind.
